package com.lemon.smartsafety.utils;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.Toast;

import com.lemon.smartsafety.app.IApplication;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;




/**
 * Created by user on 2015/3/18.
 */
public class CommonUtil {

    public static Application APP;
    public static Context context = IApplication.context();




    public static boolean strIsEmpty(String txt) {

        if (txt == null || txt.equals("")) {
            return true;
        }
        return false;
    }

    public static boolean strArrayEmpty(String[] str) {

        if (str != null && str.length != 0) {
            return true;
        }
        return false;
    }


    public static boolean listIsEmpty(List list) {

        if (list == null || list.size() == 0) {
            return true;
        }
        return false;
    }

    public static boolean bmpIsEmpty(Bitmap bitmap) {

        if (bitmap== null) {
            return true;
        }
        return false;
    }


    public static boolean viewIsEmpty(View view) {

        if (view == null) {
            return true;
        }
        return false;
    }


    public static boolean objIsEmpty(Object o) {

        if (o == null) {
            return true;
        }
        return false;
    }


    public static boolean isWeb(String email) {
        try {
            boolean tag = true;

            final String pattern1 = "(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?";
            final Pattern pattern = Pattern.compile(pattern1);
            final Matcher mat = pattern.matcher(email);

            if (!mat.find()) {
                tag = false;
            }

            return tag;
        } catch (Exception e) {
        }

        return false;
    }


    public static void toMsg(String msg) {
        try {
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void toMsgLong(String msg) {
        try {
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
